import { de } from "element-plus/es/locales.mjs";
import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 选项试api
// export const useStore = defineStore("store", {
//   state: () => ({
//     count: 18,
//   }),
//   // 计算属性
//   getters: {
//     doubleCount: (state) => state.count * 2,
//   },
//   actions: {
//     increment() {
//       this.count++;
//     },
//     decrement() {
//       this.count--;
//     },
//   },
// });

// composition API
// 组合式API
const useDoubleCount = (count: number) => {
  return count * 2;
};
const useIncrement = (count: number) => {
  return {
    increment: () => {
      count++;
    },
  };
};
const useDecrement = (count: number) => {
  return {
    decrement: () => {
      count--;
    },
  };
};
export const useStore = defineStore("store", () => {
  const count = ref(18);
  // const doubleCount = computed(() => count.value * 2);
  const doubleCount = useDoubleCount(count.value);

  // function increment() {
  //   count.value++;
  // }
  const increment = useIncrement(count.value);

  // function decrement() {
  //   count.value--;
  // }
  const decrement = useDecrement(count.value);
  return {
    count,
    doubleCount,
    increment,
    decrement,
  };
});
